import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:situation/app/router/router_name.dart';
import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/data/request/intell_request.dart';
import 'package:situation/data/store/config_store.dart';
import 'package:situation/domain/intell/intell_history_dto.dart';
import 'package:situation/domain/user/task.dart';
import 'package:situation/shared/shared.dart';
import 'package:situation/shared/util/util_mk.dart';
import 'package:situation/widgets/PlayVideo.dart';
import 'package:situation/widgets/app/app_intell.dart';
import 'package:situation/widgets/mk_load_image.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class IntellInfo extends StatefulWidget {
  const IntellInfo({super.key});

  @override
  State<IntellInfo> createState() => _IntellInfoState();
}

class _IntellInfoState extends State<IntellInfo> {
  int current = 1;
  int size = 10;

  List<IntellHistoryDto> dataList = [];

  String lat = '';
  String lon = '';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    String? position = UtilSp.getString(
      AppConstant.DEVICE_POSITION,
      defValue: '',
    );
    if (position != null && position.isNotEmpty) {
      lat = position.split(",")[0];
      lon = position.split(",")[1];
    }
    getData();
  }

  getData() async {
    dataList.addAll(await IntellRequest.getMyAroundQingbao(lat, lon, 10));
    setState(() {});
  }

  Widget? itemBuilder(BuildContext context, int index) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(
          RouterName.intellInfoTimeLine,
          arguments: {"id": dataList[index].id},
        );
      },
      child: AppIntell(intell: dataList[index]),
    );
  }



  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      onRefresh: () async {
        dataList = [];
        getData();
      },

      child: ListView.builder(
        itemCount: dataList.length,
        itemBuilder: itemBuilder,
      ),
    );
  }
}
